﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Petroleum.DB;
using Petroleum.DB.Model;
using HZH_Controls;
using Petroleum.Model;

namespace Petroleum.UC.Public
{
    public partial class GridTable_TextBox : UserControl, HZH_Controls.Controls.IDataGridViewCustomCell
    {
        private Pressure m_object = null;
        private string attribute = "";

        /// <summary>
        /// 
        /// </summary>
        /// <param name="attribute">属性</param>
        /// <param name="type">文本框属性</param>
        public GridTable_TextBox(string attribute, TextInputType type =  TextInputType.NotControl)
        {
            InitializeComponent();
            this.attribute = attribute;
            txtInput.InputType = type;
        }
        public GridTable_TextBox()
        {
            InitializeComponent();
            //this.attribute = attribute;
            //txtInput.InputType = type;
        }
        public void SetBindSource(object obj)
        {
            if (obj is Pressure)
                m_object = (Pressure)obj;
        }
        void SetObejct(string attribute) 
        {
            string value = txtInput.InputText;
            
            switch (attribute)
            {
                case "FormationPressureCoefficient":
                    m_object.Formation_Coe = value;
                    break;
                case "SSTVD":
                    m_object.SSTVD = int.Parse(value);
                    //TVD  = 0-SSTVD+KB
                    m_object.TVD = 0 - int.Parse(value) + Session.BasicInf.KB;
                    break;
                case "CollapsePressureCoefficient":
                    m_object.CollapsePressureCoefficient = value;
                    break;
                case "FormationFracturePressureCoefficient":
                    m_object.FormationFracturePressureCoefficient = value;
                    break;
                default:
                    break;
            }
        }
        private void txtInput_KeyDown(object sender, KeyEventArgs e)
        {
            if(m_object != null)
            {
                Text = txtInput.InputText;
                SetObejct(attribute);
                HZH_Controls.Forms.FrmTips.ShowTipsSuccess(this.FindForm(), "选中：" + m_object.TVD);
            }
        }
    }
}
